/*
 * AGENT SHERPA
 *  
 * Assignement 2 of the Agent Oriented Software Engineering Course
 * M.Sc. in Advanced Software Engineering (Part-time)
 * University College Dublin www.ucd.ie
 *
 * Copyright (c) 2007 Chris Walsh, Aidan Morrisy and Iain Hull.
 * All rights reserved.
 */

package org.agentsherpa;

import org.agentsherpa.model.Point;

import com.agentfactory.platform.interfaces.Perceptor;

/**
 * The LocationPerceptor provides agent beliefs, for its current location It
 * interfaces with the LocationModule to provide this data.
 */
public class LocationPerceptor extends Perceptor {
    /**
     * percieve the current state of the known map.
     * 
     * This is only an example of possible beliefs.
     */
    public void perceive() {
        System.out.println("LocationPerceptor: start");
        try {
            SimulatorService simulator = getSimulator();
            Point location = simulator.getLocation(this.agent);
            System.out.println("LocationPerceptor: " + location);
            adoptBelief("BELIEF(location" + location + ")");
        }
        catch(PerceptorException e) {
            e.printStackTrace();
        }
        System.out.println("LocationPerceptor: end");
    }
    
    private SimulatorService getSimulator() throws PerceptorException {
        SimulatorService simulator = (SimulatorService) getService("org.agentsherpa.SimulatorService");
        if (simulator == null) {
            throw new PerceptorException("Cannot access SimulatorService");
        }
        return simulator;
    }

}
